#include "Image.h"
#include <string.h>

Image::Image(char *path)
{
	//unsigned char *data;
	//data = stbi_load(path, &m_Width, &m_Height, &m_Channels, 0);

	//if (data) {
	//	m_data = new unsigned char[m_Width*m_Height*m_Channels];
	//	memcpy(m_data, data, m_Width*m_Height*m_Channels);
	//}
	//stbi_image_free(data);
	stbi_set_flip_vertically_on_load(true);
	m_data = stbi_load(path, &m_Width, &m_Height, &m_Channels, 0);
	if (!m_data) {
		printf("%s load fail, error:%s\n", path, stbi_failure_reason());
		getchar();
	}
}

Image::~Image()
{
	if(m_data)
		stbi_image_free(m_data);
}

unsigned char *Image::getData()
{
	return m_data;
}

int Image::getWidth()
{
	return m_Width;
}

int Image::getHeight()
{
	return m_Height;
}

int Image::getChannel()
{
	return m_Channels;
}